package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.ResignationCertificate;
import com.amsp.oa.oademo.mapper.ResignationCertificateMapper;
import com.amsp.oa.oademo.service.ResignationCertificateService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class ResignationCertificateServiceImpl extends ServiceImpl<ResignationCertificateMapper, ResignationCertificate>
        implements ResignationCertificateService {

    @Override
    public Page<ResignationCertificate> getPage(Integer pageNum, Integer pageSize, String employeeName,
            String idNumber) {
        LambdaQueryWrapper<ResignationCertificate> queryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.isNotBlank(employeeName)) {
            queryWrapper.like(ResignationCertificate::getEmployeeName, employeeName);
        }

        if (StringUtils.isNotBlank(idNumber)) {
            queryWrapper.like(ResignationCertificate::getIdNumber, idNumber);
        }

        queryWrapper.orderByDesc(ResignationCertificate::getCreateTime);

        return page(new Page<>(pageNum, pageSize), queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveBatch(List<ResignationCertificate> list) {
        return super.saveBatch(list);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIds(List<Long> ids) {
        return removeByIds(ids);
    }
}